/**
 * 改变按钮状态
 */
import { permiseStatus } from "./buttonPermise";
import { useDynamicButtonStore } from "@/stores/modules/dynamicButton";
const dynamicButton = useDynamicButtonStore();
// 主表按钮改变事件
export const setButtonStatus = (typeStr: string) => {
  console.log("执行主要按钮改变状态", typeStr);
  const data = permiseStatus[typeStr];
  console.log(data);

  if (data) {
    dynamicButton.buttonList.forEach((item: any) => {
      if (item.list) {
        item.list.forEach((item2: any) => {
          if (data.includes(item2.alias)) {
            item2.disabled = false;
          } else {
            item2.disabled = true;
          }
        });
      }
      if (data.includes(item.alias)) {
        item.disabled = false;
      } else {
        item.disabled = true;
      }
    });
  }
};
// 全文按钮改变事件
export const setFulltextButtonStatus = (typeStr: string) => {
  console.log("执行全文按钮改变状态", typeStr);
  const data = permiseStatus[typeStr];
  if (data) {
    dynamicButton.fulltextButtonList.forEach((item: any) => {
      if (data.includes(item.alias)) {
        item.disabled = false;
      } else {
        item.disabled = true;
      }
    });
  }
};
// 子级表格按钮改变事件
export const setChildButtonStatus = (typeStr: string) => {
  console.log("执行子表按钮改变状态", typeStr);
  const data = permiseStatus[typeStr];
  if (data) {
    dynamicButton.childButtonList.forEach((item: any) => {
      if (item.list) {
        item.list.forEach((item2: any) => {
          if (data.includes(item2.alias)) {
            item2.disabled = false;
          } else {
            item2.disabled = true;
          }
        });
      }
      if (data.includes(item.alias)) {
        item.disabled = false;
      } else {
        item.disabled = true;
      }
    });
  }
};
